package cn.tedu.finance.controller;

import cn.tedu.base.response.JsonResult;
import cn.tedu.finance.pojo.dto.InvoiceQuery;
import cn.tedu.finance.pojo.dto.InvoiceSaveParam;
import cn.tedu.finance.pojo.vo.InvoiceVO;
import cn.tedu.finance.service.InvoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/finance/invoice")
public class InvoiceController {
    @Autowired
    InvoiceService invoiceService;

    @GetMapping("select")
    public JsonResult selectInvoice(InvoiceQuery invoiceQuery) {
        log.info("查询发票信息:{}", invoiceQuery);
        List<InvoiceVO> list = invoiceService.selectInvoice(invoiceQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveInvoice(InvoiceSaveParam invoiceSaveParam) {
        log.debug("保存报销申请：{}", invoiceSaveParam);
        invoiceService.saveInvoice(invoiceSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("cancel/{id}")
    public JsonResult cancelApplication(@PathVariable Long id) {
        log.debug("取消发票申请：{}", id);
        invoiceService.cancelApplication(id);
        return JsonResult.ok();
    }

}
